package android.test;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by dinhthao on 6/20/13.
 */
public class CallLogArrayAdapter extends BaseAdapter{

    private LayoutInflater inflater;
    private static ArrayList<CallLogModel> listAdapter;

    public CallLogArrayAdapter(Context context, ArrayList<CallLogModel> adapter){
        listAdapter = adapter;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return listAdapter.size();
    }

    @Override
    public Object getItem(int i) {
        return listAdapter.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if(view == null){
            view = inflater.inflate(R.layout.list_item, null);
            holder = new ViewHolder();
            holder.tv_name = (TextView)view.findViewById(R.id.nameTV);
            holder.tv_number = (TextView) view.findViewById(R.id.numberTV);
            holder.tv_date = (TextView) view.findViewById(R.id.dateTV);
            holder.tv_duration = (TextView) view.findViewById(R.id.durationTV);
            view.setTag(holder);

        }else {
            holder = (ViewHolder) view.getTag();
        }

        holder.tv_name.setText(listAdapter.get(position).getName());
        holder.tv_number.setText(listAdapter.get(position).getNumber());
        holder.tv_date.setText(listAdapter.get(position).getDate());
        holder.tv_duration.setText(listAdapter.get(position).getDuration());
        return view;
    }

    public static class  ViewHolder{
        TextView tv_name;
        TextView tv_number;
        TextView tv_date;
        TextView tv_duration;

    }
}
